<?php
// +----------------------------------------------------------------------
// | TwoThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.twothink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 小矮人  82550565@qq.com <www.twothink.cn>
// +----------------------------------------------------------------------
namespace addons\adver\model;

use app\common\model\AddonsBase;
use addons\adver\validate\AdvsrDetails as validateAdvsrDetails;
/**
 * 分类模型
 */
class AdvsrDetails extends AddonsBase{
    protected $insert = ['start_time','end_time'];

    protected function setStartTimeAttr($value){
        return $value?strtotime($value):time();
    }
    protected function setEndTimeAttr($value){
        return $value?strtotime($value):time();
    }

    protected function getStartTimeAttr($value){
        if($value == 0){
            return date('Y-m-d H:i:s',time());
        }
        return date('Y-m-d H:i:s',$value);
    }

    protected function getEndTimeAttr($value){
        if($value == 0){
            return date('Y-m-d H:i:s',time());
        }
        return date('Y-m-d H:i:s',$value);
    }

    public function editData($data = false, $id = '')
    {
        if(!$data)
            $data = request()->param();
        $validate = new validateAdvsrDetails;
        if (!$validate->check($data)) {
            $this->error = $validate->getError();
            return false;
        }
        return parent::editData($data, $id); // TODO: Change the autogenerated stub
    }
}